#ifndef WIDEGET_HPP_
#define WIDEGET_HPP_

#include <stddef.h>           /* needed for definition of NULL */
#include <stddef.h>

#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>


//#include "common.h"
#include "ComAPI.h"

#include "GUI.H"
#include "SimLcd.h"



#define FONT_HEIGHT     (48)
#define FONT_WIDTH      (48)
/*
   #define KEY_NULL		0
   #define KEY_UP			'R'
   #define KEY_DOWN		'T'
   #define KEY_OK			'\r'
   #define KEY_ESC			'\033'
   #define KEY_RIGHT		'S'
   #define KEY_LEFT		'Q'
 */

#define    KEY_NULL                     0
#define    KEY_UP                       0x01
#define    KEY_LEFT                     0x02
#define    KEY_RIGHT                    0x04
#define    KEY_DOWN                     0x08
#define    KEY_ESC                      0x10
#define    KEY_OK                       0x20


#define DATA_HEX    1
#define DATA_DEC    2
#define DATA_ASC    3
#define DATA_BIN    4
#define DATA_PUREDEC   5

#define MENU_TIMEOUT    1000

struct AppKeyStruct
{
    char key;
    int idle;
};
struct ListBoxItemStruct
{
    char *text;
    unsigned char haveNo;
    int (*fun)(void *);
    void *arg;
};

//#if defined(__cplusplus)
//extern "C" { /* Make sure we have C-declarations in C++ programs */
//#endif

void WIDGET_Lock(void);
void WIDGET_UnLock(void);

struct AppKeyStruct GetKey(void);
int LCD_GetmaxCharPerLine(void);
int LCD_GetmaxLinePerScreen(void);
int LCD_GetFontWidth();
int LCD_GetFontHeight();
void DrawGdFont16x16(const char text[], int x, int y);

int GUI_DispStringAtLock(const char *s, int x, int y, GUI_COLOR fColor, GUI_COLOR bColor);
int GUI_DispStringHCenterAtLock(const char *s, int x, int y, GUI_COLOR fColor, GUI_COLOR bColor);
void GUI_DrawRectLock(int x0, int y0, int x1, int y1);

int MsgBox(char msg[], char retKey, int retTime);
int EditBox(int y, char title[], char text[], int retTime, int txtSize, int dataType);
int MsgBoxSaveParam(int retTime, int msgType, char *title);
int EditPasswordBox(int y, char title1[], char text[], int retTime, int txtSize, int dataType, bool fMask = true);
int EditDateBox(int y, char title1[], char title2[], char text[], int retTime, int txtSize, int dataType);


//#if defined(__cplusplus)
//}
//#endif

extern bool g_LocalUpgrade;

class CMyListBox
{
public:
    CMyListBox();
    ~CMyListBox();
    int Run(int x, char title[], struct ListBoxItemStruct item[], int retKey, int retTime);
    int Run(int x, int y, int titleGap, int textGap, bool fFocus, char title[], struct ListBoxItemStruct menu[], int retKey, int retTime);
    int key;
    short item;

private:
    short curItem;
    short startItem;
    short totalItem;
    short haveTitle;
};

#endif /* WIDEGET_HPP_ */
